# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: Andrey Vihrov <andrey.vihrov@gmail.com>
# Contributor: Frank Vanderham <twelve.eighty@gmail.com>
# Contributor: Jacob McSwain <jacob.a.mcswain@gmail.com>
# Contributor: Thomas Braby <thomas@mykolab.com>

pkgname=broadcom-wl-dkms
pkgver=6.30.223.271
pkgrel=36
pkgdesc='Broadcom 802.11 Linux STA wireless driver'
arch=(loong64 x86_64)
url='https://www.broadcom.com/site-search?filters[pages][content_type][type]=and&filters[pages][content_type][values][]=Downloads&page=1&per_page=10&q=802.11%20linux%20sta%20wireless%20driver'
license=(custom)
depends=(dkms)
conflicts=(broadcom-wl)
install=broadcom-wl-dkms.install
source=(broadcom-wl-dkms.conf
        dkms.conf.in
        001-null-pointer-fix.patch
        002-rdtscl.patch
        003-linux47.patch
        004-linux48.patch
        005-debian-fix-kernel-warnings.patch
        006-linux411.patch
        007-linux412.patch
        008-linux415.patch
        009-fix_mac_profile_discrepancy.patch
        010-linux56.patch
        011-linux59.patch
        012-linux517.patch
        013-linux518.patch
        014-linux414.patch
        015-linux600.patch
        016-linux601.patch
        "https://docs.broadcom.com/docs-and-downloads/docs/linux_sta/hybrid-v35_64-nodebug-pcoem-${pkgver//./_}.tar.gz")
b2sums=('7c4eaa825a37358509a08e5105665eeabc9f097945b6fa163cd5722b00638da5889f5466bd2c5f1b01172f2d0c9fb195f6e18329f2880adb2774406684cbc4c0'
        '69d746e11208a4bdd93cd1eaefd8ba3ba1034c150fbbf576a468b7f6775098d041b7f5db89dd1c562a9e7f7f0e72277c652a7cd3fb918e7805181ad345a12b0c'
        '038150b9a50025dbd3c81d09755956216b83c0b54db29dc4bfbc3b46bd67cf4640ad643d69ba7f8d486f52cedeb00929b97e02152e72404e6126a05855f97d6f'
        'bbc80e1ac01683ccc2d940212347fc11c74bdc252d492ca79a292015ac25df6a153ac97cb6c0f0a8d51c1c33d5dc0de4fdd61b1958499b946dc817d29646b72f'
        'ecf3eb75f8eb3331b0a36b39851536de43cffd3b303db9e9f4fe6fe55d463c3343aba17a99668448427764a719e15e3e862d6a3dc0bc61cb68da9934fb427c6f'
        '7e091ac44616ea4cfa80b3a5563f4c6a235d2431b911f6bc52074a76b2c1d609dc546430f048abf042f862907f573c6b1dfa24c8c424aeefe73ff13ae3f34900'
        '3b65cccde7ed80bd88bf945cca6b71fca9eccc4a910666dad4df56a24471535e1d6007e1ea24567002c927357b525683b02c6a7ad2986aca738fc81ab736219f'
        '28ef5e50fa11fc15b409f3b3ee42aaf329756354ba8b7923d1b27939a6b21bd64b72a4adfb2eeff3c48bb8c4c1bc4294e8fd7744b83768974bf5d0592e20c148'
        '06035b1bca121c72b5e6bf120df644d5496d6020cf8537ec83917bb0f5b5a0a25129730f46201da2cc61e48cbcf4e9d3ed7757f3223e1d3b6e29b531c4c8fabb'
        '091e1da266ebaa0d429663facf3e81c849fe900c446e1c270ba23b65c15a99efeb1ae6c20905dfcc21b5f4bc3f91b32eb3b7bc9841f2a23508c71312403af774'
        '7c8012fa51592a3fca6dfde7a7a9c6dd37eb6c406d3f8695927e32c9e714c3faa23295b116a6cd97ec0403b123747b9095883bd7e3abe6c1888c3c9a4630f9f4'
        '21f7fc163ffcf6857f3a21a8519a42600fd6b3658d14b32191ef1142c817c10c8dc691a3bc39228927ac29d7b7ac5c3a62eb786853046bacb9cc74efb51b6cb0'
        'c1f522f6554a7bfe0f7b789b042ada14316ecc87bc196c83bec95f684152f323a4c31f60ff26843e36338b8c7949bf36719a5c8afa439ff71f7c74dae4c755b6'
        'd84d08161530bb9f05f627ec798a0897643869ea9b80781ae9eee85b072922c52e5127e55f04265c53fcfedc4e9da166eb3bb9f9fc2e139d62517ec54c2f45bb'
        'e5ae3570dc2f27105c50e6dec807c1f4f1a2824995e0951e7ff405114d519e4f33992d8d2ea2c2d4fc3f9271d57f89bfb5b6b5c79af2c89492209a86ad673456'
        '0b1075bd59e8046969052ceb9cbe305ac2373b5d1600701ffcffb5219d3765ef5d15465c3aff63bbc547ed4f663dc4816d1b4fa09176d6c78828e488a9a863c4'
        '7d4dfe48577456436d0932bd1eca78fc1f0a952e141f13641b93bb24161a9f6847152966631cc05a6d707f9cf8adbded55a19aeaa2c15c963fffb5db9eff9f63'
        '6c627b392a5b05248e3fb78c9be0329deee601b70d88334f5f61e1af14643a7367fabbf3d3fce23b0cae317456ecdc7e7985ce019c3bc283117f3ba2be5b25b5'
        'e9d01c1a1a63c07f720e3ee53ee3ef634ab12694135300cb0ce47ade0e9e0084967a0b6df64d983e8184240eb3defb128f650bddb7727e901d50315307f3398a')

prepare() {
  sed -e "s/@PACKAGE_VERSION@/$pkgver/" dkms.conf.in > dkms.conf
  sed -i -e '/BRCM_WLAN_IFNAME/s/eth/wlan/' src/wl/sys/wl_linux.c
  sed -i -e "/EXTRA_LDFLAGS/s|\$(src)/lib|/usr/lib/$pkgname|;/GE_49 :=/s|:= .*|:= 1|" Makefile
}

package() {
  local dest="$pkgdir/usr/src/${pkgname/-dkms/}-$pkgver"
  install -Dm644 Makefile "$dest/Makefile"
  install -Dm644 dkms.conf "$dest/dkms.conf"
  install -Dm644 -t "$dest/patches" *.patch
  cp -a src "$dest"
  install -Dm644 lib/wlc_hybrid.o_shipped \
    "$pkgdir/usr/lib/$pkgname/wlc_hybrid.o_shipped"
  install -Dm644 broadcom-wl-dkms.conf \
    "$pkgdir/usr/lib/modprobe.d/broadcom-wl-dkms.conf"
  install -Dm644 lib/LICENSE.txt \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
